<?php
class Sql extends PDO {
	
	protected $dsn;
	protected $username;
	protected $password;
	
	public function __construct() {	

		$global = $this->getConfig();
		
		$this->dsn = $global['type'] . ':host=' . $global['host'] . ';dbname=' . $global['database'];
		$this->username = $global['user'];
		$this->password = $global['pass'];
		
		parent::__construct($this->dsn, $this->username, $this->password);
	}

	protected function getConfig()
	{
		if (!file_exists($global)) {
			throw new Exception('Arquivo global.php nao existe.');
		}

		return include_once 'config/global.php';
	}
}
